package cn.wolfcode.controller;

import cn.wolfcode.domain.BalanceDetail;
import cn.wolfcode.domain.UserWallet;
import cn.wolfcode.service.IBalanceDetailService;
import cn.wolfcode.service.IUserWalletService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController("/userWallet")
public class BalanceDetailController {

    @Autowired
    private IUserWalletService      userWalletService;
    @Autowired
    private IBalanceDetailService   balanceDetailService;

    @GetMapping("/list")
    public String listByUser(Long userId) {

        // 1: 判断用户是否登录以及是否为当前登录用户

        // 根据ID查询钱包
        UserWallet userWallet = userWalletService.byUserId(userId);
        // 根据钱包ID查询消费记录
        List<BalanceDetail> list = balanceDetailService.listByWalletId(userWallet.getId());

        // 也可以在表里存储用户ID,直接查询用户ID的记录
        return "查询用户消费明细接口";
    }
}
